<template>
  <div class="xtx-checkbox" @click="toggle">
    <i v-if="modelValue" class="iconfont icon-checked"></i>
    <i v-else class="iconfont icon-unchecked"></i>
    <span>
      <slot></slot>
    </span>
  </div>
</template>
<script>
export default {
  name: 'XtxCheckbox',
  props: { modelValue: { type: Boolean, default: false } },
  setup (props, { emit }) {
    // 用户点击，切换状态
    const toggle = () => {
      emit('update:modelValue', !props.modelValue)
      emit('change', !props.modelValue)
    }
    return { toggle }
  }
}
</script>
<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
